home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / protect-your-privacy / p.g.p. / pgpamiga / contrib / ced / decryptpgp.ced next >
Text File  |  1996-02-26  |  5KB  |  195 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*  DecryptPGP.ced - ARexx program that integrates Cygnus Editor and  */
  4. /*                   the Pretty Good Privacy package, version 1.0     */
  5. /*                                                                    */
  6. /*  This program was tested to work with Cygnus Editor 3.5 and PGP    */
  7. /*  version 2.3a patchlevel 3 by Peter Simons, but should work also   */
  8. /*  with earlier versions of both PGP and CED.                        */
  9. /*  If you want to decrypt a PGP message, you have to load it into    */
  10. /*  CED, then run this macro, and sit comfortably enjoying the show   */
  11. /*  until it finishes.                                                */
  12. /*                                                                    */
  13. /* This software is in Public Domain under GNU General Public License */
  14. /*                                                                    */
  15. /*  Author: Janusz A. Urbanowicz <alex@vm.cc.uni.torun.pl>            */
  16. /*                                                                    */
  17. /*  History                                                           */
  18. /*  Version 1.0 - first public release                                */
  19. /*                                                                    */
  20. /**********************************************************************/
  21.  
  22. /*
  23.  *            $VER: DecryptPGP.ced 1.0 (4.07.1994)
  24.  */
  25.  
  26.  
  27. Trace Off
  28.  
  29. Options Results
  30.  
  31. packetstart = "'-----BEGIN PGP MESSAGE-----'"
  32. packetend = "'-----END PGP MESSAGE-----'"
  33. signedstart = "'-----BEGIN PGP SIGNED MESSAGE-----'"
  34. signedend = "'-----END PGP SIGNATURE-----'"
  35.  
  36. cmdline = '+batchmode=on T:ced$pgp.tmp -o T:ced$plain.asc'
  37. lf = '0A'X
  38.  
  39. packets = 0
  40. lpackets = 0
  41. scratch = 0
  42.  
  43. /*                               main()                           */
  44. Address Command
  45. 'GetEnv >NIL: PGPPASS'
  46. If rc ~= 0 Then
  47. Do
  48.     Address 'rexx_ced'
  49.     okay2 "Your passphrase is not set in PGPPASS variable."||lf||,
  50.     "It must be set temporarily for running PGP".||lf||,
  51.     "Should it be deleted (for higher security) after use ??"
  52.     If result = 1 then scratch = 1
  53.     else scratch = 0
  54.     okay1 'WARNING: Your passphrase will be visible when you type it in.'
  55.     getstring "'  '  'Please enter passphrase.'" 
  56.     pgppass = result
  57.     pgppass = Strip(pgppass,'B')
  58.     Address Command
  59.     'SetEnv PGPPASS '||'"'||pgppass||'"'
  60. End
  61.  
  62. Address 'rexx_ced'
  63. okay2 "Do you want to mark decrypted blocks"||lf||,
  64.       "within the text ?"
  65. mark = result
  66.  
  67. Do until lpackets == packets
  68.     lpackets = packets
  69.     scan(mark)
  70. End
  71. If packets = 0 Then okay1 "No PGP ASCII packet found."
  72. Else okay1 "Found "||packets||" packet(s)."
  73. Exit
  74.  
  75. /*                       End of main()                     */
  76.  
  77. scan: procedure expose lf cmdline scratch packets packetstart signedstart packetend signedend
  78. Arg mark
  79. Address 'rexx_ced'
  80. If FindStart(packetstart) Then
  81. Do
  82.     If FindEnd(packetend) Then
  83.     Do
  84.         cut block
  85.         menu 0 6 0 'T:ced$pgp.tmp' /* save block to file */
  86.         decrypt_pkt(mark)
  87.         Return 1
  88.     End
  89. End
  90.  
  91. If FindStart(signedstart) Then
  92. Do
  93.     If FindEnd(signedend) Then
  94.     Do
  95.         cut block
  96.         menu 0 6 0 'T:ced$pgp.tmp' /* save block to file */
  97.         decrypt_pkt(mark)
  98.         Return 1
  99.     End
  100. End
  101. Return 0
  102.  
  103. FindStart: procedure expose packets
  104. Arg string
  105. Address 'rexx_ced'
  106. beg of file
  107.  
  108. Do FOREVER
  109.     search for string
  110.     If result = 1 Then 
  111.     Do
  112.         status 59
  113.         If result = (Length(string)-2) Then
  114.         Do
  115.             packets = packets +1
  116.             mark block
  117.             Return 1
  118.         End
  119.     End
  120.     Else Return 0
  121. End
  122.  
  123. FindEnd: procedure expose lf scratch
  124. Arg string
  125. Address = 'rexx_ced'
  126. Do FOREVER
  127.     search for string
  128.     If result = 0 Then
  129.     Do
  130.         okay1 "Cannot find end of packet."||lf,
  131.               "File is corrupted"
  132.         Call quit
  133.     End
  134.     Else
  135.     Do 
  136.         status 59
  137.         If result = (Length(string)-2) Then
  138.         Do
  139.             down
  140.             Return 1
  141.         End
  142.     End
  143. End
  144.  
  145. decrypt_pkt: procedure expose cmdline lf scratch
  146. arg mark
  147.  
  148. plainstart = "======== BEGIN OF PGP BLOCK ========"
  149. plainend = "======== END OF PGP BLOCK ========"
  150.  
  151. Address Command
  152. 'PGP '||cmdline
  153. If ~Exists('T:ced$plain.asc') Then
  154. Do
  155.     Address 'rexx_ced'
  156.     include file 'T:ced$pgp.tmp'
  157.     okay1 "Wrong passphrase !"
  158.     Address Command
  159.     Call quit
  160. End
  161. Else
  162. Do
  163.     Address 'rexx_ced'
  164.     If mark == 1 Then
  165.     Do
  166.         text plainstart
  167.         text lf
  168.         up
  169.         center line
  170.         text plainend
  171.         text lf
  172.         up
  173.         center line
  174.         up
  175.         beg of line
  176.     End
  177.     include file 'T:ced$plain.asc'
  178.     status 21
  179.     Call clean
  180.     Return 1
  181. End
  182.  
  183. clean: procedure
  184. Address Command
  185. If Exists('T:ced$pgp.tmp') Then 'Delete T:ced$pgp.tmp quiet'
  186. If Exists('T:ced$plain.asc') Then 'Delete T:ced$plain.asc quiet'
  187. If Exists('T:ced$pgp.tmp.bak') Then 'Delete T:ced$pgp.tmp.bak quiet'
  188. If Exists('T:ced$pgp.tmp.info') Then 'Delete T:ced$pgp.tmp.info quiet'
  189. Return 1
  190.  
  191. quit: procedure expose scratch
  192. Call clean
  193. If scratch == 1 Then 'Delete env:PGPPASS'
  194. Exit 0 
  195.